#pragma once
#include "stdafx.h"
#include <atlbase.h>
#include <atlcoll.h>
#include <Sensorsapi.h>
#include <sensors.h>
#include <SensAPI.h>
#include <initguid.h>
#include <propkeydef.h>
#include <comutil.h>

DEFINE_PROPERTYKEY(SENSOR_DATA_TYPE_ANGULAR_VELOCITY_X_DEGREES_PER_SECOND,  0X3F8A69A2, 0X7C5, 0X4E48, 0XA9, 0X65, 0XCD, 0X79, 0X7A, 0XAB, 0X56, 0XD5, 10); //[VT_R8]
DEFINE_PROPERTYKEY(SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Y_DEGREES_PER_SECOND,  0X3F8A69A2, 0X7C5, 0X4E48, 0XA9, 0X65, 0XCD, 0X79, 0X7A, 0XAB, 0X56, 0XD5, 11); //[VT_R8]
DEFINE_PROPERTYKEY(SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Z_DEGREES_PER_SECOND,  0X3F8A69A2, 0X7C5, 0X4E48, 0XA9, 0X65, 0XCD, 0X79, 0X7A, 0XAB, 0X56, 0XD5, 12); //[VT_R8]

DEFINE_PROPERTYKEY(SENSOR_DATA_TYPE_MAGNETIC_HEADING_COMPENSATED_MAGNETIC_NORTH_DEGREES ,	0X1637D8A2, 0X4248, 0X4275, 0X86, 0X5D, 0X55, 0X8D, 0XE8, 0X4A, 0XED, 0XFD, 11); //[VT_R8]
DEFINE_PROPERTYKEY(SENSOR_DATA_TYPE_MAGNETIC_HEADING_COMPENSATED_TRUE_NORTH_DEGREES ,		0X1637D8A2, 0X4248, 0X4275, 0X86, 0X5D, 0X55, 0X8D, 0XE8, 0X4A, 0XED, 0XFD, 12); //[VT_R8]
DEFINE_PROPERTYKEY(SENSOR_DATA_TYPE_MAGNETIC_HEADING_MAGNETIC_NORTH_DEGREES ,				0X1637D8A2, 0X4248, 0X4275, 0X86, 0X5D, 0X55, 0X8D, 0XE8, 0X4A, 0XED, 0XFD, 13); //[VT_R8]
DEFINE_PROPERTYKEY(SENSOR_DATA_TYPE_MAGNETIC_HEADING_TRUE_NORTH_DEGREES ,					0X1637D8A2, 0X4248, 0X4275, 0X86, 0X5D, 0X55, 0X8D, 0XE8, 0X4A, 0XED, 0XFD, 14); //[VT_R8]


class CSensorManagerEvents;

class CSensorEvents: public ISensorEvents
{
public:
//	CSensorEvents(void);
	CSensorEvents(CSensorManagerEvents *sensorManagerEvents);
	~CSensorEvents(void);

	// These three methods are for IUnknown
	STDMETHOD(QueryInterface)(REFIID riid, void** ppObject );
	ULONG _stdcall AddRef();
	ULONG _stdcall Release();

	// ISensorEvents method overrides
	STDMETHOD(OnStateChanged)(ISensor* pSensor, SensorState state);
	STDMETHOD(OnDataUpdated)(ISensor* pSensor, ISensorDataReport* pNewData);
	STDMETHOD(OnEvent)(ISensor* pSensor, REFGUID eventID, IPortableDeviceValues* pEventData);
	STDMETHOD(OnLeave)(REFSENSOR_ID sensorID);

	// Helper functions, also called by parent SensorManagerEvents class
	HRESULT GetSensorData(ISensor* pSensor);
	int SetStandard(int value);

private:
	// Member variable to implement IUnknown reference count
	LONG m_lRefCount;
	LONG icnt;
	// Helper functions
	HRESULT UpdateXYZ();
	HRESULT GetSensorData(ISensor* pSensor, ISensorDataReport* pDataReport);

	CSensorManagerEvents* m_pSensorManagerEvents; // Parent class for callbacks
	double mapXYZ[3];
	int stand;
};

